//
//  HWXuanzePanxuView.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/12/23.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWXuanzePanxuView.h"


@interface HWXuanzePanxuView()<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic) UIView *grayView;
@property(strong,nonatomic) UIView *whiteView;
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) NSArray *dataAray;
@property(strong,nonatomic) NSMutableArray *selectedMuArray;

@end


@implementation HWXuanzePanxuView


-(UITableView *)mainaTableVie {
    
    if (_mainaTableVie == nil
        ) {
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 10, 110, 30 *3) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.scrollEnabled = NO;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        
        
    }
    return   _mainaTableVie ;
}

- (instancetype)initWithFrame:(CGRect)frame  {
    
    if (self  = [super initWithFrame:frame]) {
        // 添加灰色背景
        [self addgrayView];
        
        [self setupUI];
        
        
    }
    return  self;
    
}


//  设置UI
- (void)setupUI {
    
    
    self.whiteView = [[UIView alloc]init];
    self.whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.whiteView];
    
    self.whiteView.layer.cornerRadius = 10;
    self.whiteView.layer.masksToBounds = YES;
    
    
    UIView *fengexianView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
    fengexianView.backgroundColor = RGB(215, 215, 215);
    //  fengexianView.backgroundColor = [UIColor orangeColor];
    [self.whiteView addSubview:fengexianView];
    
    
    self.dataAray = @[@"最新发布", @"价格倒序",@"价格升序"];
    
    
    self.dataAray = @[[HWjianzhiduiObject keylocalization:@"最新发布"],[HWjianzhiduiObject keylocalization:@"价格倒序"],[HWjianzhiduiObject keylocalization:@"价格升序"]];
    
    
    self.selectedMuArray = [[NSMutableArray alloc]init];
    [self.selectedMuArray addObject:@(NO)];
    [self.selectedMuArray addObject:@(NO)];
    [self.selectedMuArray addObject:@(NO)];
  //  [self.selectedMuArray addObject:@(NO)];
    
    //添加UItableView
    [self.whiteView addSubview:self.mainaTableVie];
    






    
    
    
    
    
    
    
    
    
    
}
- (void)relayoutTheChildControls {
    // self.whiteView.backgroundColor = [UIColor redColor];
    self.whiteView.frame = CGRectMake(10, self.whibackvieY, 110, 30*3+20);
    self.grayView.frame = CGRectMake(0, self.whibackvieY, kScreenW, kScreenH-self.whibackvieY );
    
    
    
    
}






// 添加灰色View
-(void)addgrayView {
    
    self.grayView = [[UIView alloc]init];
    self.grayView.frame  = CGRectMake(0,300, 400, 400);
    
    self.grayView.backgroundColor =  RGB(51, 51, 51);
    self.grayView.alpha = 0.6;
    [self addSubview:self.grayView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
    //  tap.delegate = self;
    [self.grayView addGestureRecognizer:tap];
    
    
    
    
}

- (void)tapView:(UITapGestureRecognizer *)touch {
    
    [touch.view.superview removeFromSuperview];
    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
    
    
}


#pragma mark --------   点击一些按钮操作
// 点击重置按钮
- (void)chongtap {
    
    DLog(@"重置按钮");
        self.selectedMuArray = [[NSMutableArray alloc]init];
       [self.selectedMuArray addObject:@(YES)];
       [self.selectedMuArray addObject:@(NO)];
       [self.selectedMuArray addObject:@(NO)];
       [self.mainaTableVie reloadData];
}

// 点击确定按钮






//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//
//    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
//
//        return NO;
//    }else if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableView"]) {
//
//
//        return NO;
//    }
//    return YES;
//
//
//}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
     return  self.dataAray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID  = @"cellID";
    
    UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell  = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
    }
    
    cell.textLabel.text = [NSString stringWithFormat:@" %@",self.dataAray[indexPath.row]] ;
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    cell.textLabel.textColor = RGB(68, 68, 68);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    return  cell;
    
    
    
    
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"xiaopingguo");
    
       [self removeFromSuperview];
    [self.delagate HWXuanzePanxuViewZhong:(int)indexPath.row];
    
    
    
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  30;
}



@end
